﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

public partial class View_Admin_KetBan_QLKetBan : System.Web.UI.Page
{
    QLKetBan kb = new QLKetBan();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            GridView1.DataSource = kb.Load_KetBan();
            GridView1.DataBind();
        }
    }
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        StringCollection idCollection = new StringCollection();
        string strID = string.Empty;

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chkDelete = (CheckBox)
               GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
            if (chkDelete != null)
            {
                if (chkDelete.Checked)
                {
                    string makb = GridView1.DataKeys[i].Value.ToString();
                    idCollection.Add(makb);
                }
            }
        }
        Xoa(idCollection);

        GridView1.DataSource = kb.Load_KetBan();
        GridView1.DataBind();
    }
    private void Xoa(StringCollection idCollection)
    {
        string IDs = "";
        foreach (string id in idCollection)
        {
            IDs = id.ToString();
            try
            {
                kb.Del_KB(int.Parse(IDs));
                lblThongBao.Visible = true;
                lblThongBao.Text = "Xóa Thành Công.";
            }
            catch (Exception)
            {
                lblThongBao.Visible = true;
                lblThongBao.Text = "Xóa không Thành Công.";
            }
        }
    }
}
